package com.csoa.community.singletons;

import java.io.File;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Environment;
import android.text.TextPaint;
import android.widget.TextView;

import com.csoa.community.activity.EmailDetailActivity;
import com.csoa.community.bean.UserBean;
import com.csoa.community.utils.AndroidUtils;
import com.csoa.community.utils.StorageCheckor;

public class GlobalVars extends Application {

	private static GlobalVars _inst = new GlobalVars();
	public static int width;
	public static int height;

	// 命名空间
	public static final String serviceNameSpace = "http://tempuri.org/";
	// 公文等请求URL
	public static final String serviceDocURL = "http://www.cshb.gov.cn/CsWebMobile/Service.svc";

	// 邮件等请求URL
	public static final String serviceEmailURL = "http://www.cshb.gov.cn/CsWebMobile/MailInterface.svc";
	// SoapAction
	public static final String soapDocAction = "http://tempuri.org/IArchives/";

	public static final String soapEmailAction = "http://tempuri.org/IMailInterface/";

	public static GlobalVars getInst() {
		return _inst;
	}

	private Context c;

	public void init(Context c) {
		this.c = c;
	}

	public static final String ALBUM_PATH = "/mnt/sdcard/dcim/100MEDIA";
	public static boolean isDebug = true;
	// 内存中保留登录用户信息
	public static SharedPreferences sharedPreferences;
	public static int MESSAGE_NOTICE_TIME = 1000;

	public static final String DATABASE_NAME = "chinaface.db";

	public String getAppPath() {
		try {
			if (StorageCheckor.checkSdcard(null)) {
				if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO) {

					return c.getExternalFilesDir(null) + "/CSOA/";
				} else {
					return new File(Environment.getExternalStorageDirectory()
							+ "/CSOA/").getAbsolutePath();
				}
			} else {
				if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO) {
					return c.getFilesDir() + "/CSOA/";
				} else {
					return new File(Environment.getExternalStorageDirectory()
							+ "/CSOA/").getAbsolutePath();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public boolean hasSDCard() {
		return StorageCheckor.checkSdcard(null);
	}

	public String getAppImgPath() {
		String appPath = getAppPath();
		if (appPath == null) {
			return appPath;
		} else {
			return getAppPath() + "img";
		}
	}

	public String getAttachPath() {
		return Environment.getExternalStorageDirectory() + "/CSOA/";
	}

	/**
	 * 打开本地附件
	 */
	public boolean isAttachExists(Context context, String fileName) {
		boolean isExists = false;
		String path = GlobalVars.getInst().getAttachPath() + fileName;
		File fileAttach = new File(path);
		if (fileAttach.exists()) {
			AndroidUtils.fileInvoke(context, path);
			isExists = true;
		}
		return isExists;
	}

	// 清除缓存
	public void clearAttachCache() {
		File cachePath = new File(GlobalVars.getInst().getAttachPath());
		if (null != cachePath && cachePath.exists()) {
			File[] files = cachePath.listFiles();
			if (files != null) {
				for (int i = 0; i < files.length; i++) {
					if (files[i].exists()) {
						files[i].delete();
					}
				}
			}
		}
	}

	public static final int pageCount = 10;

	public static final String ACCOUNT_SWITCH = "account_switch";

	/**
	 * 设置中文粗体
	 */
	public static void setBoldFont(TextView tv) {
		TextPaint tp = tv.getPaint();
		tp.setFakeBoldText(true);
	}

	public static final String LOGIN = "login";
	public static final String LOGIN_USERNAME = "username";
	public static final String LOGIN_PASSWORD = "password";
	public static final String LOGIN_IS_REMEMBER_USERNAME = "is_remember_username";
	public static final String LOGIN_IS_REMEMBER_PASSWORD = "is_remember_password";
	public static final String LOGIN_IS_AUTO_LOGIN = "is_auto_login";
	public static final String LOGIN_CURRENT_LOGIN_STATE_SIGN = "current_login_state";
	// 屏幕亮度
	public static final String LOGIN_CURRENT_SCREEAN_BRIGHT = "current_screen_bright_state";
	// 首页receiver
	public static final String ACTION_BROADCASTRECEIVEE = "com.csoa.count";
	public static final int HAVE_READ = 0;
	public static final int TO_BE_READ = 1;
	// 附件下载
	public static final int NOTICE_ID = 0x01;
	public static final int UPGRADE_ID = 0x02;
	public static final String LOGIN_REALLY_USERNAME = "really_username";

	// 已读，未读标识
	public static String READ_TYPE = "readType";
	public static String READ_TYPE_TO_BE_READ = "toBeRead";
	public static String READ_TYPE_HAVE_READ = "haveRead";
	// 签发
	public static String ISSUED = "issued";
	public static String ISUPDATE = "isupdate";

	// 当前用户状态
	public static UserBean currentUser;

	// 屏幕亮度（夜间模式）
	public static final int screenBrightValue = 50;

	// 获取数据的天数
	public static int DataCount = 7;

}
